package sword;

/**
 * @Author: 海琳琦
 * @Date: 2022/5/28 21:05
 * https://leetcode.cn/problems/he-wei-sde-liang-ge-shu-zi-lcof/
 */
public class Title57 {

    /**
     * 双指针
     * @param nums
     * @param target
     * @return
     */
    public int[] twoSum(int[] nums, int target) {
        int left = 0, right = nums.length - 1;
        while (left < right) {
            int sum = nums[left] + nums[right];
            if (sum < target) {
                left++;
            } else if (sum > target) {
                right--;
            }else{
                return new int[]{nums[left], nums[right]};
            }
        }
        return null;
    }

    public static void main(String[] args) {

    }
}
